package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-07-06
 * Time: 13:08
 */
class Alg<T extends Comparable<T>>{
    public T findMax(T[] arry){
        T max  = arry[0];
        for (int i = 1; i < arry.length; i++) {
            if(max.compareTo(arry[i]) < 0){
                max = arry[i];
            }
        }
        return max;
    }
}
class Alg2{
    public static<T extends Comparable<T>> T findMax(T[] arry){
        T max  = arry[0];
        for (int i = 1; i < arry.length; i++) {
            if(max.compareTo(arry[i]) < 0){
                max = arry[i];
            }
        }
        return max;
    }

}
public class Test {
    public static void main(String[] args) {
        Integer[] arry = {1,5,2,7,18,6};
        Integer max = Alg2.<Integer>findMax(arry);
        System.out.println(max);
    }
    public static void main1(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] arry = {1,5,2,7,18,6};
        Integer max = alg.<Integer>findMax(arry);
        System.out.println(max);
    }
}
